package top.continew.admin.generator.task;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import top.continew.admin.common.enums.TaskStatusEnums;
import top.continew.admin.generator.model.entity.TaskAssignmentDO;
import top.continew.admin.generator.service.SmsService;
import top.continew.admin.generator.service.TaskAssignmentService;
import top.continew.admin.generator.service.TaskListService;
import top.continew.admin.system.model.entity.user.UserDO;
import top.continew.admin.system.service.UserService;

import java.util.*;
import java.util.stream.Collectors;

/**
 * 任务通知定时器
 *
 * @author jiangjun
 * @since 2025/01/20 10:00
 */
@Slf4j
@Component
@RequiredArgsConstructor
public class TaskNotificationScheduler {

    private final TaskListService taskListService;
    private final TaskAssignmentService taskAssignmentService;
    private final UserService userService;

    /**
     * 每日9点推送微信消息
     */
    @Scheduled(cron = "0 0 9 * * ?")
    public void pushWxMsgAt9AM() {
        log.info("开始执行每日9点微信消息推送");
        try {
            taskListService.pushWxMsgToProvinceHandlers();
            log.info("每日9点微信消息推送完成");
        } catch (Exception e) {
            log.error("每日9点微信消息推送失败", e);
        }
    }

    /**
     * 每日14点推送微信消息
     */
    @Scheduled(cron = "0 0 14 * * ?")
    public void pushWxMsgAt2PM() {
        log.info("开始执行每日14点微信消息推送");
        try {
            taskListService.pushWxMsgToProvinceHandlers();
            log.info("每日14点微信消息推送完成");
        } catch (Exception e) {
            log.error("每日14点微信消息推送失败", e);
        }
    }

    /**
     * 每周一、周三9点统计未处理任务并发送短信
     */
    @Scheduled(cron = "0 0 9 * * MON,WED")
    public void sendSmsNotificationTwiceWeekly() {
        log.info("开始执行每周一、周三短信通知任务");
        try {
            //taskListService.pushSmsMsgToProvinceHandlers();
            log.info("每周一、周三短信通知任务完成");
        } catch (Exception e) {
            log.error("每周一、周三短信通知任务失败", e);
        }
    }
}